package com.glsc.ngateway.opmanage.service;

import com.glsc.ngateway.common.base.domain.mysql.gateway.other.FileCenterTranData;
import com.glsc.ngateway.common.base.repo.mysql.gateway.other.FileCenterTranDataRepository;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class FileCenterTranDataService {


    @Resource
    private FileCenterTranDataRepository fileCenterTranDataRepository;

    /**
     * 根据条件查询第三方导入数据的一条
     *
     * @param condition
     * @return
     */
    public FileCenterTranData findByCondition(FileCenterTranData condition) {
        if (Objects.isNull(condition)) {
            return null;
        }
        List<FileCenterTranData> dataList = listByCondition(condition);
        if (CollectionUtils.isNotEmpty(dataList)) {
            return dataList.get(0);
        }
        return null;
    }

    /**
     * 根据条件查询第三方导入数据集合
     *
     * @param condition
     * @return
     */
    public List<FileCenterTranData> listByCondition(FileCenterTranData condition) {
        if (Objects.isNull(condition)) {
            return null;
        }
        List<FileCenterTranData> dataList = fileCenterTranDataRepository.findAll(Example.of(condition));
        if (CollectionUtils.isNotEmpty(dataList)) {
            return dataList;
        }
        return null;
    }

    /**
     * 保存所有
     *
     * @param datas
     * @return
     */
    public List<FileCenterTranData> saveAll(List<FileCenterTranData> datas) {
        return fileCenterTranDataRepository.saveAll(datas);
    }


}
